import { matchSorter } from "match-sorter";

/**
 * This is just matching a hard-coded list of values, but often you'd be
 * querying your database for a set of records. If you're using prisma with
 * postgres, you can use "fulltext" to let the database make it really fast for
 * you:
 * https://www.prisma.io/docs/concepts/components/prisma-client/full-text-search
 */
export async function searchLangs(query: string) {
  // artificially slowed down and chaotic where some requests start earlier but
  // land later, this is a condition many apps don't consider but Remix handles
  // for you automatically. Open the network tab and watch as Remix
  // automatically cancels the requests as they're interrupted.
  await new Promise((res) => setTimeout(res, Math.random() * 1000));
  return matchSorter(langs, query, { keys: ["alpha2", "name"] });
}

const langs = [
  { name: "Afar", alpha2: "aa" },
  { name: "Abkhazian", alpha2: "ab" },
  { name: "Avestan", alpha2: "ae" },
  { name: "Afrikaans", alpha2: "af" },
  { name: "Akan", alpha2: "ak" },
  { name: "Amharic", alpha2: "am" },
  { name: "Aragonese", alpha2: "an" },
  { name: "Arabic", alpha2: "ar" },
  { name: "Assamese", alpha2: "as" },
  { name: "Avaric", alpha2: "av" },
  { name: "Aymara", alpha2: "ay" },
  { name: "Azerbaijani", alpha2: "az" },
  { name: "Bashkir", alpha2: "ba" },
  { name: "Belarusian", alpha2: "be" },
  { name: "Bulgarian", alpha2: "bg" },
  { name: "Bihari languages", alpha2: "bh" },
  { name: "Bislama", alpha2: "bi" },
  { name: "Bambara", alpha2: "bm" },
  { name: "Bengali", alpha2: "bn" },
  { name: "Tibetan", alpha2: "bo" },
  { name: "Breton", alpha2: "br" },
  { name: "Bosnian", alpha2: "bs" },
  { name: "Catalan; Valencian", alpha2: "ca" },
  { name: "Chechen", alpha2: "ce" },
  { name: "Chamorro", alpha2: "ch" },
  { name: "Corsican", alpha2: "co" },
  { name: "Cree", alpha2: "cr" },
  { name: "Czech", alpha2: "cs" },
  {
    name: "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic",
    alpha2: "cu",
  },
  { name: "Chuvash", alpha2: "cv" },
  { name: "Welsh", alpha2: "cy" },
  { name: "Danish", alpha2: "da" },
  { name: "German", alpha2: "de" },
  { name: "Divehi; Dhivehi; Maldivian", alpha2: "dv" },
  { name: "Dzongkha", alpha2: "dz" },
  { name: "Ewe", alpha2: "ee" },
  { name: "Greek, Modern (1453-)", alpha2: "el" },
  { name: "English", alpha2: "en" },
  { name: "Esperanto", alpha2: "eo" },
  { name: "Spanish; Castilian", alpha2: "es" },
  { name: "Estonian", alpha2: "et" },
  { name: "Basque", alpha2: "eu" },
  { name: "Persian", alpha2: "fa" },
  { name: "Fulah", alpha2: "ff" },
  { name: "Finnish", alpha2: "fi" },
  { name: "Fijian", alpha2: "fj" },
  { name: "Faroese", alpha2: "fo" },
  { name: "French", alpha2: "fr" },
  { name: "Western Frisian", alpha2: "fy" },
  { name: "Irish", alpha2: "ga" },
  { name: "Gaelic; Scottish Gaelic", alpha2: "gd" },
  { name: "Galician", alpha2: "gl" },
  { name: "Guarani", alpha2: "gn" },
  { name: "Gujarati", alpha2: "gu" },
  { name: "Manx", alpha2: "gv" },
  { name: "Hausa", alpha2: "ha" },
  { name: "Hebrew", alpha2: "he" },
  { name: "Hindi", alpha2: "hi" },
  { name: "Hiri Motu", alpha2: "ho" },
  { name: "Croatian", alpha2: "hr" },
  { name: "Haitian; Haitian Creole", alpha2: "ht" },
  { name: "Hungarian", alpha2: "hu" },
  { name: "Armenian", alpha2: "hy" },
  { name: "Herero", alpha2: "hz" },
  {
    name: "Interlingua (International Auxiliary Language Association)",
    alpha2: "ia",
  },
  { name: "Indonesian", alpha2: "id" },
  { name: "Interlingue; Occidental", alpha2: "ie" },
  { name: "Igbo", alpha2: "ig" },
  { name: "Sichuan Yi; Nuosu", alpha2: "ii" },
  { name: "Inupiaq", alpha2: "ik" },
  { name: "Ido", alpha2: "io" },
  { name: "Icelandic", alpha2: "is" },
  { name: "Italian", alpha2: "it" },
  { name: "Inuktitut", alpha2: "iu" },
  { name: "Japanese", alpha2: "ja" },
  { name: "Javanese", alpha2: "jv" },
  { name: "Georgian", alpha2: "ka" },
  { name: "Kongo", alpha2: "kg" },
  { name: "Kikuyu; Gikuyu", alpha2: "ki" },
  { name: "Kuanyama; Kwanyama", alpha2: "kj" },
  { name: "Kazakh", alpha2: "kk" },
  { name: "Kalaallisut; Greenlandic", alpha2: "kl" },
  { name: "Central Khmer", alpha2: "km" },
  { name: "Kannada", alpha2: "kn" },
  { name: "Korean", alpha2: "ko" },
  { name: "Kanuri", alpha2: "kr" },
  { name: "Kashmiri", alpha2: "ks" },
  { name: "Kurdish", alpha2: "ku" },
  { name: "Komi", alpha2: "kv" },
  { name: "Cornish", alpha2: "kw" },
  { name: "Kirghiz; Kyrgyz", alpha2: "ky" },
  { name: "Latin", alpha2: "la" },
  { name: "Luxembourgish; Letzeburgesch", alpha2: "lb" },
  { name: "Ganda", alpha2: "lg" },
  { name: "Limburgan; Limburger; Limburgish", alpha2: "li" },
  { name: "Lingala", alpha2: "ln" },
  { name: "Lao", alpha2: "lo" },
  { name: "Lithuanian", alpha2: "lt" },
  { name: "Luba-Katanga", alpha2: "lu" },
  { name: "Latvian", alpha2: "lv" },
  { name: "Malagasy", alpha2: "mg" },
  { name: "Marshallese", alpha2: "mh" },
  { name: "Maori", alpha2: "mi" },
  { name: "Macedonian", alpha2: "mk" },
  { name: "Malayalam", alpha2: "ml" },
  { name: "Mongolian", alpha2: "mn" },
  { name: "Marathi", alpha2: "mr" },
  { name: "Malay", alpha2: "ms" },
  { name: "Maltese", alpha2: "mt" },
  { name: "Burmese", alpha2: "my" },
  { name: "Nauru", alpha2: "na" },
  { name: "Bokm\u00e5l, Norwegian; Norwegian Bokm\u00e5l", alpha2: "nb" },
  { name: "Ndebele, North; North Ndebele", alpha2: "nd" },
  { name: "Nepali", alpha2: "ne" },
  { name: "Ndonga", alpha2: "ng" },
  { name: "Dutch; Flemish", alpha2: "nl" },
  { name: "Norwegian Nynorsk; Nynorsk, Norwegian", alpha2: "nn" },
  { name: "Norwegian", alpha2: "no" },
  { name: "Ndebele, South; South Ndebele", alpha2: "nr" },
  { name: "Navajo; Navaho", alpha2: "nv" },
  { name: "Chichewa; Chewa; Nyanja", alpha2: "ny" },
  { name: "Occitan (post 1500)", alpha2: "oc" },
  { name: "Ojibwa", alpha2: "oj" },
  { name: "Oromo", alpha2: "om" },
  { name: "Oriya", alpha2: "or" },
  { name: "Ossetian; Ossetic", alpha2: "os" },
  { name: "Panjabi; Punjabi", alpha2: "pa" },
  { name: "Pali", alpha2: "pi" },
  { name: "Polish", alpha2: "pl" },
  { name: "Pushto; Pashto", alpha2: "ps" },
  { name: "Portuguese", alpha2: "pt" },
  { name: "Quechua", alpha2: "qu" },
  { name: "Romansh", alpha2: "rm" },
  { name: "Rundi", alpha2: "rn" },
  { name: "Romanian; Moldavian; Moldovan", alpha2: "ro" },
  { name: "Russian", alpha2: "ru" },
  { name: "Kinyarwanda", alpha2: "rw" },
  { name: "Sanskrit", alpha2: "sa" },
  { name: "Sardinian", alpha2: "sc" },
  { name: "Sindhi", alpha2: "sd" },
  { name: "Northern Sami", alpha2: "se" },
  { name: "Sango", alpha2: "sg" },
  { name: "Sinhala; Sinhalese", alpha2: "si" },
  { name: "Slovak", alpha2: "sk" },
  { name: "Slovenian", alpha2: "sl" },
  { name: "Samoan", alpha2: "sm" },
  { name: "Shona", alpha2: "sn" },
  { name: "Somali", alpha2: "so" },
  { name: "Albanian", alpha2: "sq" },
  { name: "Serbian", alpha2: "sr" },
  { name: "Swati", alpha2: "ss" },
  { name: "Sotho, Southern", alpha2: "st" },
  { name: "Sundanese", alpha2: "su" },
  { name: "Swedish", alpha2: "sv" },
  { name: "Swahili", alpha2: "sw" },
  { name: "Tamil", alpha2: "ta" },
  { name: "Telugu", alpha2: "te" },
  { name: "Tajik", alpha2: "tg" },
  { name: "Thai", alpha2: "th" },
  { name: "Tigrinya", alpha2: "ti" },
  { name: "Turkmen", alpha2: "tk" },
  { name: "Tagalog", alpha2: "tl" },
  { name: "Tswana", alpha2: "tn" },
  { name: "Tonga (Tonga Islands)", alpha2: "to" },
  { name: "Turkish", alpha2: "tr" },
  { name: "Tsonga", alpha2: "ts" },
  { name: "Tatar", alpha2: "tt" },
  { name: "Twi", alpha2: "tw" },
  { name: "Tahitian", alpha2: "ty" },
  { name: "Uighur; Uyghur", alpha2: "ug" },
  { name: "Ukrainian", alpha2: "uk" },
  { name: "Urdu", alpha2: "ur" },
  { name: "Uzbek", alpha2: "uz" },
  { name: "Venda", alpha2: "ve" },
  { name: "Vietnamese", alpha2: "vi" },
  { name: "Volap\u00fck", alpha2: "vo" },
  { name: "Walloon", alpha2: "wa" },
  { name: "Wolof", alpha2: "wo" },
  { name: "Xhosa", alpha2: "xh" },
  { name: "Yiddish", alpha2: "yi" },
  { name: "Yoruba", alpha2: "yo" },
  { name: "Zhuang; Chuang", alpha2: "za" },
  { name: "Chinese", alpha2: "zh" },
  { name: "Zulu", alpha2: "zu" },
];

export type Lang = { name: string; alpha2: string };
